﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Eassets.Layered.Domain;
using System.Data.SqlClient;
using System.Data;
using System.Collections.ObjectModel;

namespace Eassets.Data
{
  public class CompanyData
    {

        //public void Insert(Company company)
        //{
        //    SqlCommand command = new SqlCommand("SP_InsertCompany"); // Name of the SP
        //    command.Parameters.AddWithValue("@CompanyCode", company.CompanyCode);
        //    command.Parameters.AddWithValue("@CompanyName", company.CompanyName);
            
        //    try
        //    {
        //         CommonData commonData = new CommonData();commonData.ExecuteNonQuery(ConstructCommand(command, company));
        //    }
        //    catch (Exception e)
        //    {

        //    }
        //}

        //public SqlCommand ConstructCommand(SqlCommand command, Company company)
        //{
        //    command.CommandType = CommandType.StoredProcedure;

        //    return command;
        //}

        //public void Delete(int companyId)
        //{
        //    SqlCommand command = new SqlCommand("SP_DeleteCompany");

        //    command.CommandType = CommandType.StoredProcedure;
        //    command.Parameters.AddWithValue("@CompanyId", companyId);

        //     CommonData commonData = new CommonData();commonData.ExecuteNonQuery(command);
        //}

        //public void Update(Company company)
        //{
        //    SqlCommand command = new SqlCommand("SP_UpdateCompany");
        //    command.Parameters.AddWithValue("@CompanyId", company.CompanyId);
        //     CommonData commonData = new CommonData();commonData.ExecuteNonQuery(ConstructCommand(command, company));
        //}

        //public Collection<Company> GetAllCompany()
        //{
        //    SqlCommand command = new SqlCommand("SP_GetAllCompanies");
        //    command.CommandType = CommandType.StoredProcedure;


        //    CommonData commonData = new CommonData(); SqlDataReader dataReader = commonData.ExecuteReader(command);

        //    Collection<Company> Companys = new Collection<Company>();
        //    Company company;

        //    while (dataReader.Read())
        //    {
        //        company = new Company();
        //        company.CompanyId = Convert.ToInt16(dataReader["CompanyId"]);
        //        if (String.IsNullOrEmpty(Convert.ToString(dataReader["CompanyId"])))
        //        {
        //            company.CompanyId = 0;
        //        }
        //        else
        //        {
        //            company.CompanyId = Convert.ToInt16(dataReader["CompanyId"]);
        //        }
        //        company.CompanyCode = Convert.ToString(dataReader["CompanyCode"]);
        //        company.CompanyName = Convert.ToString(dataReader["CompanyName"]);

        //        Companys.Add(company);
        //    }
        //    dataReader.Close();
        //    return Companys;
        //}
    }
}
